/**
 *
 */
package com.david.mydemo.util;

import java.util.HashMap;

import org.springframework.http.HttpStatus;

/**
 * @author My
 *
 */
public class MyResponse extends HashMap<String, Object>{
	private static final long serialVersionUID = -8713837118340960775L;

	public MyResponse success() {
		this.code(HttpStatus.OK);
		this.message("success");
		this.data(null);
		return this;
	}

	public MyResponse success(Object data) {
		this.code(HttpStatus.OK);
		this.message("success");
		this.data(data);
		return this;
	}

	public MyResponse isUsed(Object data) {
		this.code(HttpStatus.IM_USED);
		this.message("success");
		this.data(data);
		return this;
	}

	public MyResponse success(Object data, String message) {
		this.code(HttpStatus.OK);
		this.message(message);
		this.data(data);
		return this;
	}

	public MyResponse fail() {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(null);
		this.message("error");
		return this;
	}

	public MyResponse fail(String message) {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(null);
		this.message(message);
		return this;
	}

	public MyResponse uploadFail(String message) {
		this.code(HttpStatus.NOT_EXTENDED);
		this.data(null);
		this.message(message);
		return this;
	}

	public MyResponse fail(HttpStatus status, Object data, String message) {
		this.code(status);
		this.data(data);
		this.message(message);
		return this;
	}

	public MyResponse fail(Object data, String message) {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(data);
		this.message(message);
		return this;
	}

	public MyResponse code(HttpStatus status) {
		this.put("code", status.value());
		return this;
	}

	public MyResponse code(int code) {
		this.put("code", code);
		return this;
	}

	public MyResponse message(String message) {
		this.put("message", message);
		return this;
	}

	public MyResponse data(Object data) {
		this.put("data", data);
		return this;
	}

	@Override
	public MyResponse put(String key, Object value) {
		super.put(key, value);
		return this;
	}

}
